package gui;

import java.awt.Color;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
//ScenicsMatrix类构造打印景区景点分布图的界面
public class ScenicsMatrix extends JFrame {
	//实例化一个Scenic类的对象
	function.Scenic scenic = new function.Scenic();
	//调用scenic类的getTotalNumber方法获取景点的数量
	int n=scenic.getTotalNumber();
	private JPanel scenicsMatrixPanel;
	//生成行数和列数都为景点数的邻接矩阵
	private function.AdjacencyMatrix am=new function.AdjacencyMatrix(n);

	public ScenicsMatrix() {
		super("景区景点分布图");
		setSize(1350, 550);
		setLocation(250, 200);

		Font font = new Font("宋体", Font.PLAIN, 20);
		UIManager.put("OptionPane.font", font);
		UIManager.put("OptionPane.messageFont", font);
		UIManager.put("OptionPane.buttonFont", font);

		setVisible(true);
	}

	
	public void scenicsMatrixPanel() {
		scenicsMatrixPanel = new JPanel();
		scenicsMatrixPanel.setLayout(null);
		//调用AdjacencyMatrix类的create方法构建邻接矩阵
		am.create();
		
		JLabel informationLabel = new JLabel("");
		informationLabel.setBounds(50, 50, 90, 30);
		informationLabel.setFont(new Font("宋体", Font.PLAIN, 20));
		informationLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		scenicsMatrixPanel.add(informationLabel);
		
		for(int i=0;i<n;i++) {
			//循环调用Scenic类的findNameByNumber方法构建界面表格的第一行（表头）
			JLabel informationLabel1 = new JLabel(scenic.findNameByNumber(i));
			informationLabel1.setBounds(50+(i+1)*90, 50, 90, 30);
			informationLabel1.setFont(new Font("宋体", Font.PLAIN, 20));
			informationLabel1.setBorder(BorderFactory.createLineBorder(Color.BLACK));
			scenicsMatrixPanel.add(informationLabel1);
		}

		for(int i=0;i<n;i++) {
			for(int j=-1;j<n;j++) {
				JLabel informationLabel2 = new JLabel("");
				informationLabel2.setBounds(50+(j+1)*90, 50+(i+1)*30, 90, 30);
				informationLabel2.setFont(new Font("宋体", Font.PLAIN, 20));
				informationLabel2.setBorder(BorderFactory.createLineBorder(Color.BLACK));
				scenicsMatrixPanel.add(informationLabel2);	
				
				if(j==-1) {
					//循环调用Scenic类的findNameByNumber方法构建界面表格的第一列（表头）
					informationLabel2.setText(scenic.findNameByNumber(i));
				} else {
					//填充邻接矩阵的内容，调用AdjacencyMatrix类的get方法得到两景点间的距离
					informationLabel2.setText(Integer.toString(am.get(i, j)));
				}
			}
		}
		
		scenicsMatrixPanel.setVisible(true);
		add(scenicsMatrixPanel);
		setVisible(true);
	}
}
